home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-13 | 3.7 KB | 137 lines | [TEXT/ttxt] |
- class ScrollingTextEdit(ScrollingPresenter)
- instance vars
- autoRecalc
- frame,
- _font
- end
-
- method init self {class ScrollingTextEdit} #rest args #key\
- text:myText("") \
- vertScrollBarDisplayed:(@always) \
- boundary: \
- textWidth: \
- textHeight:(300) \
- autoRecalc:(true) \
- ->
- (
- self.autoRecalc := autoRecalc
- self.frame := new Frame -- place here so that layout() is called properly
- local vScroll := new SimpleScrollBar orientation:@vertical height:boundary.height
- vScroll.directDrag := true
- apply NextMethod self fill:WhiteBrush boundary:boundary \
- vertScrollBar:vScroll stationary:true args
-
- if (textWidth = unsupplied) do
- textWidth := self.clippingPresenter.width
- if (autoRecalc) do textHeight := boundary.height
- local textBounds := new Rect x2:textWidth y2:textHeight
- local target := new Text String:myText
- local te := new TextEdit target:target boundary:textBounds
- self.targetPresenter := te
- )
-
- method afterInit self {class ScrollingTextEdit} #rest args #key\
- font:(theAppFont) ->
- (
- apply NextMethod self args
- self.font := font
- self.targetPresenter.inset := new Point x:3 y:0
- self.targetPresenter.selectionBackground := whiteBrush
- )
-
- method recalcHeight self {class ScrollingTextEdit} -> (
- if (not self.autoRecalc) do return
- local tp := self.targetPresenter
- local fnt := self.font
-
- tp.height := (calculate tp @width tp.width) + fnt.fontSize + fnt.leading + fnt.descent
- layout self
- )
-
- method fontGetter self {class ScrollingTextEdit} -> self._font
- method fontSetter self {class ScrollingTextEdit} newFont ->
- (
- self._font := newFont
- local textP := self.targetPresenter
- setDefaultAttr textP @font newFont.font
- setDefaultAttr textP @leading newFont.leading
- setDefaultAttr textP @size newFont.fontSize
- if (self.presentedBy !== undefined) do
- recalcHeight self
- textP.cursor := new Rect x1:-1 x2:0 \
- y1:(-newFont.leading + newFont.descent) y2:0
- local vScroll := self.vertScrollBar
- if (vScroll != undefined) do
- vScroll.stepAmount := newFont.leading
- newFont
- )
-
- method widthSetter self {class ScrollingTextEdit} val ->
- (
- local tp := self.targetPresenter
-
- nextMethod self val
- tp.width := self.clippingPresenter.width
- if (self.presentedBy !== undefined) do
- recalcHeight self
- val
- )
-
- method recalcRegion self {class ScrollingTextEdit} ->
- (
- NextMethod self
- if (self.frame <> undefined) do
- SetBoundary self.frame self.boundary
- local vScroll := self.vertScrollBar
- if (vScroll != undefined) do
- vScroll.pageAmount := self.clippingPresenter.height - self.font.leading
- )
-
- method draw self {class ScrollingTextEdit} surface clip ->
- (
- NextMethod self surface clip
- if (self.frame != undefined) do
- drawLoweredFrame self.frame surface clip self.globalTransform
- )
-
- method layout self {class ScrollingTextEdit} ->
- (
- local compositor := self.compositor
- if (compositor != undefined) do ignoreRefreshRegion compositor true
- NextMethod self
- if (self.frame != undefined) do (
- local clipP := self.clippingPresenter
- clipP.x := clipP.y := 2
- clipP.width := clipP.width - 4
- clipP.height := clipP.height - 4
- local vScroll := self.vertScrollBar
- if (vScroll != undefined) do (
- vScroll.x := vScroll.x - 1
- vScroll.y := 1
- vScroll.height := vScroll.height - 2
- )
- local hScroll := self.horizScrollBar
- if (hScroll != undefined) do (
- hScroll.x := 1
- hScroll.y := hScroll.y - 1
- hScroll.width := hScroll.width - 2
- )
- )
- if (compositor != undefined) do ignoreRefreshRegion compositor false
- NotifyChanged self true
- )
-
- method textGetter self {class ScrollingTextEdit} ->
- (
- self.targetPresenter.target
- )
-
- method textSetter self {class ScrollingTextEdit} newText ->
- (
- local tp := self.targetPresenter
-
- tp.target := newText as Text
- if (self.presentedBy !== undefined) do
- recalcHeight self
- )
-